import random
from django.shortcuts import render
from django.views import View
from django import http
from django_redis import get_redis_connection
import logging
logger = logging.getLogger('django')
from apps.verifications.libs.yuntongxun.ccp_sms import CCP
class SMSCodeView(View):
    def get(self,request,mobile):
        # 1. 接收参数
        image_code_client = request.GET.get('image_code')
        uuid = request.GET.get('image_code_id')
        # 2. 校验参数
        if not all([image_code_client,uuid]):
            return http.JsonResponse({'code':400,'errmsg':'缺少参数'})

        # 生成短信验证码:6位数字验证码
        sms_code = '%06d' % random.randint(0,999999)
        logger.info(sms_code)

        # celery 异步调用 使用第三方 容联云通讯讯
        from celery_tasks.sms.tasks import ccp_send_sms_code
        ccp_send_sms_code.delay(mobile, sms_code)
        # 响应结果
        return http.JsonResponse({'code':0,'errmsg':'发送成功'})